package cn.ondraw.ragflow.task;

import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import cn.ondraw.ragflow.service.impl.TokenManager;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

@Slf4j
@Component
@RequiredArgsConstructor
public class TokenRefreshTask {

    private final TokenManager tokenManager;

    /**
     * 每分钟执行一次token刷新
     */
    @Scheduled(fixedRate = 60000)
    public void refreshToken() {
        try {
            log.info("开始刷新RagFlow token");
            tokenManager.refreshToken();
            log.info("RagFlow token刷新成功");
        } catch (Exception e) {
            log.error("RagFlow token刷新失败", e);
        }
    }
}
